package com.yf.controller.api.course;

import com.yf.annotation.LoginUser;
import com.yf.dao.AccountDao;
import com.yf.entity.AccountEntity;
import com.yf.entity.UserEntity;
import com.yf.response.R;
import com.yf.service.AccountService;
import com.yf.service.UserService;
import com.yf.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/api/course/user")
@RestController
public class ApiCourseUserContoller {

    @Autowired
    private UserService userService;

    @Autowired
    private AccountService accountService;

    @GetMapping("/info")
    public R userInfo(@LoginUser UserEntity userEntity){
        UserVO userVO = userService.getUser(userEntity.getId());
        return R.ok(userVO);
    }


    /**
     * 用户账户
     * @return
     */

    @GetMapping("/account")
    public R userAccount(@LoginUser UserEntity userEntity){

        UserVO accountEntity = accountService.getAccount(userEntity.getId());

        return R.ok(accountEntity);
    }

    /**
     * 用户二维码
     * @return
     */
    @GetMapping("/qrCode")
    public R userQrCode(){
        return R.ok();
    }

    /**
     * 奖金记录
     * @return
     */
    @GetMapping("/account/record")
    public R accountRecord(){
        return R.ok();
    }

    /**
     * 用户账户
     * @return
     */
    @PostMapping("/update")
    public R updateUser(@LoginUser UserEntity userEntity,String info,String name,String phone){
        if(info==null || name == null || phone == null ){
            return R.error("输入不能为空");
        }
        userEntity.setInfo(info);
        userEntity.setName(name);
        userEntity.setPhone(phone);
        userService.update(userEntity);
        return R.ok();
    }
}
